package servlet;

import listener.SessionBindingListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(value = "/servletC")
public class ServletC extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {



        ServletContext servletContext = getServletContext();
        // 修改
        servletContext.setAttribute("key1", "value3");
        // 移除
        servletContext.removeAttribute("key2");


        HttpSession session = req.getSession();
        // 修改
        session.setAttribute("key1", "value3");
        // 移除
        session.removeAttribute("key2");

//        session.invalidate();

        // 绑定
        session.setAttribute("key1", new SessionBindingListener());

        // 解绑
        session.removeAttribute("key1");
    }
}
